package com.example.net.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

/**
 * @author zhaoyunlong
 * @date 2020/11/9
 * @description
 */
public class UDPClient {

    public static void main(String[] args) {
        try {
            //创建udp通信的socket
            DatagramSocket datagramSocket = new DatagramSocket(10000);
            //从控制台读取数据
            Scanner scanner = new Scanner(System.in);
            String str = scanner.nextLine();
            DatagramPacket datagramPacket = new DatagramPacket(str.getBytes(), str.getBytes().length, InetAddress.getByName("localhost"), 10002);
            datagramSocket.send(datagramPacket);
        }catch (Exception e) {

        }
    }
}
